package lab11.com.acme.service;

import lab11.com.acme.domain.account.CheckingAccount;
import lab11.com.acme.domain.account.SavingAccount;
import lab11.com.acme.domain.bank.Bank;
import lab11.com.acme.domain.client.Client;
import lab11.com.acme.domain.client.Gender;
import lab11.com.acme.exceptions.ClientExistsException;
import lab11.com.acme.exceptions.NotEnoughFundsException;
import lab11.com.acme.exceptions.OverDraftLimitExceededException;

public class BankApplication
{
	private static final String NOT_ENOUGH_FUNDS = "Not enough funds";

	public static void main(String[] args)
	{
		Bank myBank = new Bank(10);
		
		for (int i = 0; i < 10; i++)
		{
			Client newClient;
			if (i % 2 == 0)
			{
				newClient = new Client(Integer.toString(i), Gender.MALE);
				newClient.addAccount(new SavingAccount(i, 100 + i * 10));
			}
			else
			{
				newClient = new Client(Integer.toString(i), Gender.FEMALE);
				newClient.addAccount(new CheckingAccount(i, 100 + i * 10, 100));
			}
			try
			{
				myBank.addClient(newClient);
			}
			catch (ClientExistsException cee)
			{
				System.out.println("This client already exists.");
			}
		}
		
		try{
		BankService.depositToAll(myBank, -100d);
		} catch(IllegalArgumentException e){
			System.out.println(e);
		}
		
		try
		{
			BankService.withdrawFromSmb(myBank, 0, 1000d);
		} catch (IllegalArgumentException e)
		{
			System.out.println(e);
		} catch (NotEnoughFundsException e)
		{
			System.out.println(NOT_ENOUGH_FUNDS);
		}
		try
		{
			BankService.withdrawFromSmb(myBank, 0, -10d);
		} catch (IllegalArgumentException e)
		{
			System.out.println(e);
		} catch (NotEnoughFundsException e)
		{
			System.out.println(NOT_ENOUGH_FUNDS);
		}
		
		try
		{
			BankService.withdrawFromSmb(myBank, 1, 100000d);
		} catch (IllegalArgumentException e)
		{
			System.out.println(e);
		} catch(OverDraftLimitExceededException e)
		{
			System.out.println(e);
		} catch (NotEnoughFundsException e)
		{
			System.out.println(NOT_ENOUGH_FUNDS);
		}
		
		try
		{
			BankService.withdrawFromSmb(myBank, 1, -10d);
		} catch (IllegalArgumentException e)
		{
			System.out.println(e);
		} catch(OverDraftLimitExceededException e)
		{
			System.out.println(e);
		} catch (NotEnoughFundsException e)
		{
			System.out.println(NOT_ENOUGH_FUNDS);
		}
	}
		
}
